package com.ddpyjqtd.thread.threadcreate;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 
 * @Description: callable/future 方式实现多线程
 * 
 * @author: ddpyjqtd
 * @Date: 2019年5月13日
 *
 */
public class ByCallable {

	public static void main(String[] args) {
		Callable<String> callable = new Callable<String>() {
			@Override
			public String call() throws Exception {
				return "这个是另一个线程中的返回值";
			}
		};

		FutureTask<String> futureTask = new FutureTask<>(callable);
		new Thread(futureTask).start();
		try {
			System.out.println("线程的返回值：" + futureTask.get());
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
	}
}
